using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace PersonalAlbum.Controllers
{
    public class CaptchaController : Controller
    {
        //
        // GET: /Captcha/

        public FileResult Index()
        {
            using (Bitmap b = CaptchaManager.RenderImage())
            {
                var ms=new MemoryStream();
                b.Save(ms, ImageFormat.Gif);
                return File(ms.ToArray(), "image/png");
            }
        }

        public JsonResult Render()
        {
            WebLogger.Trace("reset captcha");
            try
            {
                CaptchaManager.ResetCaptcha();
                WebLogger.Trace("catcha was reset");
                return Json(new { success = "true" });
            }
            catch (Exception e1)
            {
                WebLogger.LogError(e1, "reset captcha");
                return Utils.JavascriptError("");
            }
           
        }

    }
}
